package com.itwill.ecom.company;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("companyService")
public class CompanyServiceImpl implements CompanyService {
	@Autowired
	CompanyDao companyDao;
	
	public CompanyServiceImpl() {
		System.out.println("#### CompanyService()");
	}

	public CompanyServiceImpl(CompanyDao companyDao) {
		System.out.println("#### CompanyService(CompanyDao CompanyDao)");
		this.companyDao = companyDao;
	}

	public void setCompanyDao(CompanyDao companyDao) {
		System.out.println("#### CompanyService : setCompanyDao(CompanyDao CompanyDao)");
		this.companyDao = companyDao;
	}

	private CompanyDao getCompanyDao() {
		System.out.println("#### CompanyService : getCompanyDao()");
		return this.companyDao;
	}

	@Override
	public boolean createCompany(CompanyBeans company){
		boolean result = false;
		
		try{
			getCompanyDao().create(company);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}

	@Override
	public List<CompanyBeans> getAllCompany(){
		List<CompanyBeans> resultList = new ArrayList<CompanyBeans>();
		
		try{
			resultList = getCompanyDao().searchAllList();
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return resultList;
	}
	
	@Override
	public CompanyBeans getCompanyByNo(int companyno){
		CompanyBeans resultBean = null;
		
		try{
			resultBean = getCompanyDao().readByNo(companyno);
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return resultBean;
	}

	@Override
	public boolean updateCompany(CompanyBeans company){
		boolean result = false;
		
		try{
			getCompanyDao().update(company);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}

	@Override
	public boolean deleteCompany(int companyno){
		boolean result = false;
		
		try{
			getCompanyDao().delete(companyno);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}
}